package com.fu.consumer.controller;

import com.fu.core.common.JsonResult;
import com.fu.core.pojo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 付龙江
 * @date 2022/1/29 16:48
 */
@RestController
@RequestMapping("/user")
@CrossOrigin
@Api(tags = "个人中心")
public class UserController {


    @PostMapping("/userMessage")
    @ApiOperation(value = "用户信息")
    public Map<String,Object> userMessage(){
        User user = new User(1,"付龙江","13440154744","成都",null,null);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("user",user);
        return jsonResult.getMap();
    }


    @PostMapping("/allOrder")
    @ApiOperation(value = "全部订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "订单状态（1完成  2代付款  3配送中  4已取消  5评价）", dataType = "Integer", required = true)
    })
    public Map<String,Object> allOrder(Integer status){
        List<List<OrderSku>> list = new ArrayList<>();
        for (int j = 0; j < 4; j++) {
            List<OrderSku> orderSkuList = new ArrayList<>();
            for (int i = 1; i < 4; i++) {
                OrderSku orderSku = new OrderSku(i,"/还没有图片","新疆大西瓜","1个装",38.00,2,76.00,i);
                orderSkuList.add(orderSku);
            }
            list.add(orderSkuList);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("allOrder",list);
        return jsonResult.getMap();
    }

    @PostMapping(value = "/orderDetail")
    @ApiOperation(value = "订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id，切记是id号  而不是订单编号", dataType = "Integer", required = true)
    })
    public Map<String,Object> orderDetail(Integer orderId){
        Map<Order,List<OrderSku>> map = new HashMap<>();
        Order order = new Order(1,"10001",1,1,11.1,21.1,1,new Timestamp(System.currentTimeMillis()),new Timestamp(System.currentTimeMillis()),
                "饿得哼",10.0,"313","付龙江","13440154744","四川省成都市双流区",
                "华府大道金茂光明城市");
        List<OrderSku> orderSkuList = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            OrderSku orderSku = new OrderSku(i,"/还没得图片","西瓜","一个装",10.00,2,20.00,i);
            orderSkuList.add(orderSku);
        }
        map.put(order,orderSkuList);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("orderDetail",map);
        return jsonResult.getMap();
    }

    @PostMapping(value = "/orderRemark")
    @ApiOperation(value = "评价订单")
    public Map<String,Object> orderRemark(@RequestBody Remark remark){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("评论成功！");
        return jsonResult.getMap();
    }

    @PostMapping(value = "/myCollectList")
    @ApiOperation(value = "我的收藏")
    public Map<String,Object> myCollectList(){
        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }


    @PostMapping(value = "/browsingHistory")
    @ApiOperation(value = "我的收藏")
    public Map<String,Object> browsingHistory(){
        List<GoodsEsVo> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            GoodsEsVo goodsEsVo = new GoodsEsVo(i,"新疆吐鲁番盆地大斜西瓜","大西瓜","西瓜","/都还没有图片",
                    new Timestamp(System.currentTimeMillis()),40.00,"个",800,4.20,1,new Date(System.currentTimeMillis()),"09:00:00",null,null);
            list.add(goodsEsVo);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }


    @PostMapping(value = "/deleteByGoodsId")
    @ApiOperation(value = "我的收藏和浏览记录做批量删除")
    public Map<String,Object> deleteByGoodsId(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setMsg("删除成功！传值方式请联系后端");
        return jsonResult.getMap();
    }
}
